<template>
	<view class="container">
		<activity :activityList="list"></activity>
		<emptyData :width="empty.width" :height="empty.height" :text="empty.text" :icon="empty.icon" :marginTop="empty.marginTop" v-if="list.length == 0"></emptyData>
	</view>
</template>

<script>
	import activity from '../../components/activity/activity.vue'
	export default {
		components: {
			activity
		},
		data() {
			return {
				type: '', //预约类型  1亲子活动,2社团活动,3展览演出,4讲座论坛
				page: 1,
				list: [],
				isIphoneX: false,
				empty: {
					width: 135,
					height: 134,
					text: '暂无数据',
					icon: '/image/emptyAddress.png',
					marginTop: 100
				},
			}
		},
		onLoad(e) {
			this.isIphoneX = this.$util.uniappIsIPhoneX()
			uni.setNavigationBarTitle({
				title: e.title
			})
			this.type = e.type;
			this.getList();
		},
		onReachBottom() {
		  this.page++
		  this.getList()
		},
		methods: {
			getList() {
			  this.$api.sendRequest({
			      url: "/api/socialize/goodslist",
			      data: {
			        page: this.page,
					page_size: 20,
			        type: this.type
			      },
			      success: res => {
			        if(res.code == 0) {
						if(this.page == 1) this.list = []
						this.list = [...this.list, ...res.data.list]

						// 循环数组，格式化开始时间和结束时间格式为08:00
						for(let i = 0; i < this.list.length; i++) {
							this.list[i].start_time = this.formatTime(this.list[i].start_time, 'HH:mm')
							this.list[i].end_time = this.formatTime(this.list[i].end_time, 'HH:mm')
						}
			        } 
			      }
			    })
			},
			formatTime(time) {
			//    time的格式是12:00:00
			   return time.substring(0, 5)
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
